#!/usr/bin/env python
'''Small command line calculator'''
from __future__ import division # Detault to real devision

__author__ = "Miki Tebeka <miki.tebeka@gmail.com>"
__license__ = "BSD" # see LICENSE

from math import * # Get all math goodies in global namespace
from optparse import OptionParser

USAGE = '''usage: %prog MATH_EXPRESSION
    e.g. calc '7 * 29' -> 203
'''

def main(argv=None):
    if argv is None:
        import sys
        argv = sys.argv

    from optparse import OptionParser

    parser = OptionParser(USAGE.strip())

    opts, args = parser.parse_args(argv[1:])
    if len(args) != 1:
        parser.error("wrong number of arguments") # Will exit

    try:
        print eval(args[0])
    except Exception, e:
        raise SystemExit("error: %s" % e)

if __name__ == "__main__":
    main()
